package com.sctvcloud.bazhong.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.base.BaseActivity;
import com.sctvcloud.bazhong.base.BaseFragment;
import com.sctvcloud.bazhong.beans.AFileItem;
import com.sctvcloud.bazhong.ui.adapter.holder.AuthorHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yuxipan on 2018-01-15.
 */

public class AuthorAdapter extends BaseHolderAbsAdapter<AFileItem, AuthorHolder> {
    public AuthorAdapter(Context context, List<AFileItem> list) {
        super(context, list);
    }

    //    public AuthorAdapter(Context context, List<AFileItem> datas) {
//        this.context = context;
//        this.items = datas;
//    }
    private BaseActivity activity;
    private BaseFragment fragment;
    private ArrayList<Pair<String, String>> pairs;


    public void setActivity(BaseActivity activity) {
        this.activity = activity;
    }

    public void setFragment(BaseFragment fragment) {
        this.fragment = fragment;
    }

    public void setPairs(ArrayList<Pair<String, String>> pairs) {
        this.pairs = pairs;
    }

    @Override
    public AuthorHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_author_afile_list, null);
        AuthorHolder holder = new AuthorHolder(context, view);
        holder.setActivity(activity);
        holder.setFragment(fragment);
        holder.setPairs(pairs);
        return holder;
    }


    @Override
    public int getItemCount() {
        return data.size();
    }

//    public void setData(List<AFileItem> data) {
//        if (items == null) {
//            items = new ArrayList<>();
//        }
//        this.items.clear();
//        this.items.addAll(data);
//        notifyDataSetChanged();
//    }

    public void addData(List<AFileItem> data) {
        if (data == null) {
            data = new ArrayList<>();
        }
        this.data.addAll(data);
        notifyDataSetChanged();
    }


}
